﻿/*
 * Сделано в SharpDevelop.
 * Пользователь: maxxadm
 * Дата: 05.09.2012
 * Время: 20:06
 * 
 * Для изменения этого шаблона используйте Сервис | Настройка | Кодирование | Правка стандартных заголовков.
 */
using System;
using Newtonsoft.Json;

namespace jellybird.core
{
	/// <summary>
	/// Description of TwCredentials.
	/// </summary>
	public class TwCredentials:IEquatable<TwCredentials>
	{
		public TwCredentials()
		{
		}
		
		public string ConsumerKey { get; set; }
		public string ConsumerSecret { get; set; }
		public string AccessToken { get; set; }
		public string AccessTokenSecret { get; set; }

		[JsonIgnore()]
		public bool IsProperlyFilled
		{
			get
			{
				if(string.IsNullOrWhiteSpace(ConsumerKey))
					return false;
				if(string.IsNullOrWhiteSpace(ConsumerSecret))
					return false;
				if(string.IsNullOrWhiteSpace(AccessToken))
					return false;
				if(string.IsNullOrWhiteSpace(AccessTokenSecret))
					return false;

				return true;
			}
		}

		public bool Equals(TwCredentials other)
		{
	
			if(other==null) return false;

			if (ConsumerKey != other.ConsumerKey) return false;
			if(ConsumerSecret!=other.ConsumerSecret) return false;
			if(AccessToken!=other.AccessToken) return false;
			if(AccessTokenSecret!=other.AccessTokenSecret) return false;
			
			return true;
		}


		#region Equals and GetHashCode implementation
		public override bool Equals(object obj)
		{
			TwCredentials other = obj as TwCredentials;
			if (other == null)
				return false;
			return this.Equals(other);
		}
		
		public override int GetHashCode()
		{
			int hashCode = 0;
			unchecked {
				if (ConsumerKey != null)
					hashCode += 1000000007 * ConsumerKey.GetHashCode();
				if (ConsumerSecret != null)
					hashCode += 1000000009 * ConsumerSecret.GetHashCode();
				if (AccessToken != null)
					hashCode += 1000000021 * AccessToken.GetHashCode();
				if (AccessTokenSecret != null)
					hashCode += 1000000033 * AccessTokenSecret.GetHashCode();
			}
			return hashCode;
		}
		
		public static bool operator == (TwCredentials lhs, TwCredentials rhs)
		{
			if (ReferenceEquals(lhs, rhs))
				return true;
			if (ReferenceEquals(lhs, null) || ReferenceEquals(rhs, null))
				return false;
			return lhs.Equals(rhs);
		}
		
		public static bool operator != (TwCredentials lhs, TwCredentials rhs)
		{
			return !(lhs == rhs);
		}
		#endregion

	}
}
